import { createRouter, createWebHistory } from 'vue-router'

import routes from './routes'
import { get_token } from '@/utils/auth';
import { check_login } from '@/api/login';

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes
})

//导航守卫
router.beforeEach(async (to, from, next) => {
  if (!to.meta.not_check) {
    if (!get_token()) {
      next('/login');
      return;
    }
    //验证当前登录信息是否过期
    const res = await check_login();
    console.log(res, "::::::");
  }

  next();
});


export default router
